package com.ly.hotel.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.util.Log;

import com.ly.hotel.msgevent.NetworkEvent;
import com.ly.hotel.adaptor.NetworkUtil;
import com.ly.hotel.common.Constants;

import de.greenrobot.event.EventBus;

public class NetworkStateReceiver extends BroadcastReceiver {
	
	@Override
	public void onReceive(Context context, Intent intent) {
		
		if(Build.BOARD.endsWith(Constants.BOARD_TYPE_ADA801_NAME) || Build.BOARD.endsWith(Constants.BOARD_TYPE_ADA628_NAME)
				|| Build.BOARD.endsWith(Constants.BOARD_TYPE_A83T_NAME)){
				
			ConnectivityManager connectMgr = (ConnectivityManager) (context.getSystemService(Context.CONNECTIVITY_SERVICE));
			NetworkInfo wifiNetInfo = connectMgr
					.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
			if (NetworkUtil.isConnected(context)) {
				int type;
				if (wifiNetInfo.isConnected()) {
					type = NetworkEvent.WIFI;
					Log.i("network","WIFI网络通了！！！！！！！！！！！！！！！！！！！！！！！！");
				} else {
					Log.i("network","有线网络通了！！！！！！！！！！！！！！！！！！！！！！！！");
					type = NetworkEvent.ETH;
				}
				EventBus.getDefault().post(new NetworkEvent(true,type));
			} else {
				Log.i("network","网络不通！！！！！！！！！！！！！！！！！！！！！！！！");
				EventBus.getDefault().post(new NetworkEvent(false,NetworkEvent.UNKNOW));
			}
		}
	}
}
